Ext.define('js.foundation.FoundationABShowPage', {
    extend: 'Ext.grid.Panel',
    id:'FoundationABShowPage',
    requires: ['js.Util', 'js.ctrl.Common',],
    controller: 'Common',
    autoScroll : true,
    margin:'30 15 30 15',
    height:'100%',
    height:508,
    bodyStyle: {
        backgroundColor: '#eee',
    },
    initComponent: function () {
        this.store = Ext.create('js.store.foundation.RfoundationSystemStore');
        this.store.getProxy().setExtraParam('pageNum', 1);
        this.store.getProxy().setExtraParam('progress_type',this.status);
        this.store.getProxy().setExtraParam('engineering_id',this.engineering_id);
        this.store.load({
            callback:function () {
                let me = Ext.getCmp('FoundationABShowPage');
                if(me){
                    if(me.store.data.items.length>0){
                        new Page({
                            id: 'paginationSupplierAbc',
                            pageTotal: me.store.data.items[0].data.pageTotal, //必填,总页数
                            pageAmount: 10,  //每页多少条
                            dataTotal: me.store.data.items[0].data.dataTotal, //总共多少条数据
                            curPage:parseInt(me.store.data.items[0].data.pageNum), //初始页码,不填默认为1
                            pageSize: 5, //分页个数,不填默认为5
                            showPageTotalFlag:true, //是否显示数据统计,不填默认不显示
                            showSkipInputFlag:true, //是否支持跳转,不填默认不显示
                            getPage: function (page) {
                                //获取当前页数
                                me.store.getProxy().setExtraParam('pageNum', page);
                                me.store.reload();
                            }
                        })
                    }else{
                        new Page({
                            id: 'paginationSupplierAbc',
                            pageTotal: 1, //必填,总页数
                            pageAmount: 10,  //每页多少条
                            dataTotal: 0, //总共多少条数据
                            pageSize: 5, //分页个数,不填默认为5
                            showPageTotalFlag:true, //是否显示数据统计,不填默认不显示
                            showSkipInputFlag:true, //是否支持跳转,不填默认不显示
                            getPage: function (page) {
                                //获取当前页数
                               ``
                                me.store.reload();
                            }
                        })
                    }
                }
            }
        });
        this.columns = [
            {text: '序号', dataIndex: 'progress_no', align: 'center', flex: 2,
                renderer: function (value, cellmeta, record, rowIndex, columnIndex, store) {//自定义列值组合
                    if(this.Zstsatus==1){
                        return `<div class="mutualA"><a herf="#">${value}</a></div>`;
                    }else{
                        return `<div class="mutualA"><a herf="#" style="color:red">${value}</a></div>`;
                    }
                },
            },
            {text: '监督日期', dataIndex: 'supervision_date', align: 'center', flex: 1,},
            {text: '监督人员', dataIndex: 'supervisor_name', align: 'center', flex: 1,},
            {text: '报验日期', dataIndex: 'inspection_date', align: 'center', flex: 1,},
            {text: '报验资料名', dataIndex: 'inspection', align: 'center', flex: 2,},
            {text: '报验人及电话', dataIndex: 'user_information', align: 'center', flex: 2,},
            {text: '是否下发</br>整改', dataIndex: 'inspection_result_text', align: 'center', flex: 1,},
            {
                text: "操作", dataIndex: 'user_id',
                flex:2,
                align: 'center',
                renderer: function (value, cellmeta, record, rowIndex, columnIndex, store) {//自定义列值组合
                    return '<span style="margin-right:20px;color:#2672d9;font-size: 14px;letter-spacing: 1px;cursor:pointer;"><a href="#" style="text-decoration:none;" onclick="xiangqinggcjdysjd(' + JSON.stringify(record.data).replace(/\"/g, "'") + ')">详情</a></span> <span style="margin-right:20px;color:#ff8041;font-size: 14px;letter-spacing: 1px;cursor:pointer;"> <a href="#" style="text-decoration:none;" onclick="updgcjdysjd(' + JSON.stringify(record.data).replace(/\"/g, "'") + ')">编辑</a></span><span style="margin-right:20px;color:#ff8041;font-size: 14px;letter-spacing: 1px;cursor:pointer;"><a href="#" style="text-decoration:none;" onclick="delgcjdysjd(' + JSON.stringify(record.data).replace(/\"/g, "'") + ')">删除</a> </span>';
                },height:44
            }
        ];
        this.dockedItems = [
            {
                dock: 'top',
                xtype: 'toolbar',
                border: 'none',
                style: {
                    backgroundColor: '#FFF',
                },
                margin: '0 0 20 0',
                items: [{
                    xtype: "button",
                    text: '添加',
                    cls: 'button-Intelligent-sensor',
                    style: "cursor:pointer",
                    margin: '0 5% 0 29%',
                    width: '9.5%',
                    scope: this,
                    handler: this.FoundactionAdd,
                    height: 40,
                    progress_type:this.status,
                    engineering_id:this.engineering_id

                },'->', {
                    xtype : "button",
                    height:'40',
                    cls: 'button-Intelligent-sensor',
                    handler: this.wancheng,
                    progress_type:this.status,
                    engineering_id:this.engineering_id,
                    engineering_no:this.engineering_no,
                    engineering_name:this.engineering_name,
                    width: '150',
                    text:'完成'
                }]
            },{
                xtype: 'panel',
                html: '<div id="paginationSupplierAbc" class="pagination"></div>',
                dock: 'bottom',
                height: 50,
                margin: '-14 0 0 0',
                displayInfo: true,
            }];
        this.callParent(arguments);
    },
    FoundactionAdd: function (btn) {
        let params = {
            engineering_id:btn.engineering_id,
            progress_type:btn.progress_type,
        };
        let btnCancel = Ext.create('Ext.button.Button', {
            cls: 'btnCancel',
            text: `取消`,
            scale: 'medium',
            width:140,
            height:42,
            margin:'0 0 20 200',
            handler: function (btn) {
                btn.up('window').close();
            },
            scope: this

        });
        let btnSubmit = Ext.create('Ext.button.Button', {
            cls:'btnSubmit',
            border:false,
            text: `保存`,
            margin: '0 0 20 30',
            width:140,
            height:42,
            scale: 'medium',
            handler: function (btn) {
                let supervision_date=Ext.getCmp('supervision_date').getValue();
               /* let user_id=Ext.getCmp('user_id_bbr').getValue();*/
                let user_name_bbr=Ext.getCmp('user_name_bbr').getValue();
                let inspection_date=Ext.getCmp('inspection_date').getValue();
                let inspection_no=Ext.getCmp('inspection_no').getValue();
                let inspection_name=Ext.getCmp('inspection_name').getValue();
                let supervision_details=Ext.getCmp('supervision_details').getValue();
                let rectification_date=Ext.getCmp('rectification_date').getValue();
                let user_ids=Ext.getCmp('supervisor_id_jdr').getValue();
                if(user_name_bbr===''||inspection_date===''||inspection_no===''){
                    Ext.toast('请将信息填写完整');
                }else  if(/^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/.test(inspection_no)==false){
                    Ext.toast('手机号码不正确');
                }else {
                    let panel =Ext.getCmp('FoundationABShowPage')
                    panel.mask('正在加载数据请稍后');
                    util.post('/progressRoutes', {
                        action_type: 'progressAdd',
                        rectification_date:rectification_date,
                        engineering_id: params.engineering_id,
                        progress_type: params.progress_type,
                        supervision_date: supervision_date,
                        reporter_name:user_name_bbr,
                        inspection_date: inspection_date,
                        inspection_no: inspection_no,
                        inspection_name: inspection_name,
                        supervision_details: supervision_details,
                        user_ids: user_ids,
                        inspection_result: Ext.getCmp('inspection_result').getValue().inspection_result ? Ext.getCmp('inspection_result').getValue() : Ext.getCmp('inspection_result').value,
                        rectification_notice: Ext.getCmp('rectification_notice').getValue(),
                        rectification_reply: Ext.getCmp('rectification_reply').getValue(),
                        remarks: Ext.getCmp('remarks').getValue(),

                    }).then(function (response) {
                        panel.unmask();
                        let obj = Ext.decode(response.responseText);
                        if (obj.success) {
                            Ext.toast('保存成功');
                            let me = Ext.getCmp('FoundationABShowPage');
                            me.store.reload();
                            btn.up('window').close();
                        } else {
                            Ext.toast(`保存失败,${obj.message}`);
                        }
                    });
                }
            },
            scope: this
        });
        let formPanel = Ext.create('js.foundation.foundationAddPage');
        let win = util.window(formPanel, {title:'添加节点记录' ,width:'58%',height:'91.5%',  buttons: ['->', btnCancel, btnSubmit, '->']});
        win.show();
    },
    wancheng:function(btn){
        let progress_type=btn.progress_type;
        let engineering_id=btn.engineering_id;
        let engineering_no=btn.engineering_no;
        let engineering_name=btn.engineering_name;
        let vim={
            xtype:'panel',
            bodyPadding: '80 0 0 120',
            defaultType: 'textfield',
            html:'<span style="font-size: 26px;font-weight: normal;letter-spacing: 1px;color: #2672d9;">您确定完成当前步骤吗？</span>',
            dockedItems: [{
                dock: 'bottom',
                xtype: 'toolbar',
                ui: 'fuck',
                height:100,
                items: [{
                    xtype: 'button',
                    cls:'tuichu',
                    text: `<span style="color:#fff">取消</span>`,
                    margin: '0 0 0 100',
                    scale: 'medium',
                    handler: function (btn) {
                        btn.up('window').close();
                    },
                }, {
                    xtype: 'button',
                    // scale: 'user',
                    arrow: true,
                    cls: 'tuichuA',
                    text: `<span style="color:#fff">确定</span>`,
                    scale: 'medium',
                    margin: '0 125 0 30',
                    scope: this,
                    handler: function(btn){
                        util.post('/progressRoutes', {
                            action_type:'progressQuery',
                            progress_type:progress_type,
                            engineering_id:engineering_id
                        }).then(function (response) {
                            let obj= Ext.decode(response.responseText);
                             if(obj.data.length<=0){
                                 Ext.toast(`请输入数据`);
                                 btn.up('window').close();
                             }else{
                                 util.post('/progressRoutes', {
                                     action_type:'progressFinish',
                                     progress_type:progress_type,
                                     engineering_id:engineering_id
                                 }).then(function (response) {
                                     let obj= Ext.decode(response.responseText);
                                     if(obj.success){
                                         Ext.toast('成功');
                                         btn.up('window').close();
                                         let newPanel=Ext.getCmp('js.information.InformationListMain');
                                         if(newPanel){
                                             newPanel.close();
                                         }
                                         util.sysPanelAdd('js.information.InformationListMain',{
                                             engineering_id:engineering_id,
                                             engineering_no:engineering_no,
                                             num:1,
                                             engineering_name:engineering_name
                                         });
                                     }else{
                                         Ext.toast(`失败,${obj.message}`);
                                     }
                                 });
                             }
                        });
                    }
                }]
            }]
        }
        let winS = util.window(vim, {title: '完成' ,height: '290', width: '500'});
        winS.show();
    }

});